package com.nexgo.payment.trans.setting.transmanage;

import android.os.Bundle;
import android.view.View;

import com.nexgo.payment.R;
import com.nexgo.payment.constrant.PreferencesConstants;
import com.nexgo.payment.databases.Repository;
import com.nexgo.payment.trans.setting.SaveParameterActivity;
import com.nexgo.payment.trans.setting.SaveParameterPresenter;
import com.nexgo.payment.widget.SwitchButton;
import com.nexgo.payment.widget.TitleBuilder;

import java.util.HashMap;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 交易刷卡控制
 *
 * @author 谭忠扬-YuriTam
 * @time 2017年8月28日
 */
public class SetupCardSwitchActivity extends SaveParameterActivity {

    @BindView(R.id.trans_void_swipe_card)
    SwitchButton transVoidSwipeCard;
    @BindView(R.id.trans_auth_com_void_swipe_card)
    SwitchButton transAuthComVoidSwipeCard;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setup_card_switch);
        ButterKnife.bind(this);
        new SaveParameterPresenter(this, Repository.getInstance());

        initTitle();
    }

    //初始化标题栏
    private void initTitle() {
        new TitleBuilder(this)
                .setExternalTitleBgRes(R.drawable.bg_blue_icon)
                .setLeftImage(R.drawable.arrow_icon)
                .setRightText(getString(R.string.action_save))
                .setTitleText(getString(R.string.trans_swipe_control))
                .build();
    }

    @Override
    protected HashMap<String, String> getDataBind() {
        HashMap<String, String> map = new HashMap<>();
        map.put(PreferencesConstants.TRANS_VOID_SWIPE_CARD, transVoidSwipeCard.isChecked() ? "1" : "0");
        map.put(PreferencesConstants.TRANS_AUTH_COM_VOID_SWIPE_CARD, transAuthComVoidSwipeCard.isChecked() ? "1" : "0");
        return map;
    }

    @Override
    public void showDetail() {
        transVoidSwipeCard.setChecked("1".equals(mPresenter.getParamValue(PreferencesConstants.TRANS_VOID_SWIPE_CARD)));
        transAuthComVoidSwipeCard.setChecked("1".equals(mPresenter.getParamValue(PreferencesConstants.TRANS_AUTH_COM_VOID_SWIPE_CARD)));
    }

    @OnClick({R.id.title_iv_left, R.id.title_tv_right})
    public void onClicked(View view) {
        switch (view.getId()) {
            case R.id.title_iv_left:
                finish();
                break;
            case R.id.title_tv_right:
                if (mPresenter != null) {
                    mPresenter.saveParams(getDataBind());
                }
                break;
            default:
                break;
        }
    }
}
